<template>
  <!-- 左上角 -->
  <div class="ranking-chart">
    <div class="base-background">
      <div class="base-h-l"></div>
      <div class="base-h-r"></div>
    </div>
    <div class="base-frame-img">
      <div class="box-title">
        <div class="box-t-icon"></div>
        <div class="box-t-text">节能率排名统计</div>
      </div>
      <div class="box-content">
        <div class="p-m-list" v-for="(item, index) in pmList" :key="'p-m-l' + index">
          <div class="p-m-item">
            <span style="color: #b9da12;font-weight: bold;line-height: 20px;">No.{{ index + 1 }}</span>&nbsp;&nbsp;
            <span class="pmi-name-text">{{ item.projectName }}</span>
            <div class="jdt-backg">
              <span class="same-load">
                <span class="load-bg" :style="`width: ${(item.energyEfficiency / 100 * 140)}px;`">
                </span>
              </span>
            </div>
            <span style="color: #fff;">{{ item.energyEfficiency + '%' }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useBigScreenStore } from "@/pinia/bigScreen";

const bsStore = useBigScreenStore();
let pmList = ref([])

watch(() => bsStore.projectId, (newValue, oldValue) => {
  if (newValue) {
    if (localStorage.getItem("big_RankingChart_all")) {
      pmList.value = JSON.parse(localStorage.getItem("big_RankingChart_all"))
    } else {
      getData();
    }
  }
})

const getData = () => {
  let arr = []
  bsStore.projectList.forEach(item => {
    if (parseFloat(item.totalPower).toFixed(2) > 0 && item.energyEfficiency !== 100) {
      arr.push(item)
    }
  });
  pmList.value = arr.sort((a, b) => { return b.energyEfficiency - a.energyEfficiency; })
  if (pmList.value.length != 0) {
    localStorage.setItem("big_RankingChart_all", JSON.stringify(pmList.value))
  }
}

onMounted(() => { });

</script>

<style lang="scss" scoped>
.base-frame-img {
  position: relative;
  margin-left: 2px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  background-size: 100% 100%;
  box-sizing: border-box;
  min-width: 390px;
  min-height: 200px;
  width: 30em;
}

.base-background {
  background: url(/src/assets/wbe4/l-bj-1-line.png) center no-repeat;
  background-size: 100% auto;
  position: absolute;
  overflow: hidden;
  padding: 2px 1px;
  cursor: pointer;
  background-color: #003f6f;
  border-radius: 15px;
  opacity: 0.9;
  min-width: 200px;
  height: 16rem;
  width: 30em;
  box-shadow: inset 0 0 40px #0fbff3;
  display: flex;
}

.base-h-l {
  background: url(/src/assets/wbe4/l-bj-l-1.png) center no-repeat;
  height: 4rem;
  width: 50%;
  background-color: #000e13;
}

.base-h-r {
  background: url(/src/assets/wbe4/l-bj-r-1.png) center no-repeat;
  height: 4rem;
  width: 50%;
  background-color: #000e13;
}

.box-title {
  display: flex;
  padding: 0.5rem 0rem;
}

.box-t-text {
  font-size: 1.4rem;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: #FFFFFF;
  line-height: 2.5rem;
  margin-left: 3px;
  user-select: none;
}

.box-t-icon {
  width: 32px;
  height: 32px;
  background: url(/src/assets/wbe4/tubiao.png) center no-repeat;
  background-size: 100% 100%;
}

.item-text {
  color: #b9ccd3;
  margin: 0.7vh 0vw;
  font-size: 14px;
}

.box-content {
  color: #fff;
  height: 11rem;
  overflow: overlay;
}

.ranking-chart {
  margin-top: 1.5rem;

  .p-m-item {
    display: flex;
    justify-content: space-between;
    margin-top: 0.66rem;

    .p-m-list {
      background: url(/src/assets/wbe4/r-l-t-i.png) center no-repeat;
      background-size: cover;
    }

    .pmi-name-text {
      width: 150px;
      color: #fff;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .jdt-backg {
      width: 225px;

      .same-load {
        display: inline-block;
        width: 70%;
        height: 10px;
        vertical-align: middle;
        border: 0.06vw solid #43c4c8;
        border-radius: 10px;
        position: relative;
      }

      .load-bg {
        background: linear-gradient(to right, #c8eb31, #31dfec, #31e786);
        height: 10px;
        display: inline-block;
        position: absolute;
        border-radius: 5px;

        i {
          animation: light1 2s ease infinite;
          position: absolute;
          left: 0;
          display: inline-block;
          width: 5px;
          height: 100%;
          border-radius: 0px 5px 5px 0px;
          box-shadow: 5px 0 30px rgba(15, 182, 252, 1);
          background: #fff;
          background: linear-gradient(90deg, #33ffdd, #aaffee);
        }

        @keyframes light1 {
          0% {
            left: 0px;
          }

          100% {
            left: 80%;
          }
        }
      }
    }
  }
}
</style>
